package com.example.design.threadLocaldemo;

import com.example.design.threadLocaldemo.CustomizeThreadPoolExecutor;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @Description
 * @Author liuzhihui
 * @Date 2024/7/8
 */
@Slf4j
public class ThreadTest {

    private static ThreadPoolExecutor executorService = new CustomizeThreadPoolExecutor(2,2,30, TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(100));

    public static void main(String[] args) {
        ThreadLocal<String> requestAttributesHolder = RequestHolder.requestAttributesHolder;
        log.info("父线程:" + requestAttributesHolder.get());

        executorService.submit(()->{
            MyThread thread = (MyThread) Thread.currentThread();
//            String s = threadLocal.get();
//            log.info("子线程:" + s);
            System.out.println();
        });
    }

    public static class RequestHolder {
        public static final ThreadLocal<String> requestAttributesHolder = new ThreadLocal<>();
        static {
            requestAttributesHolder.set("request data");
        }
    }
}
